<?php
namespace MobileHome\Controller;
use Think\Page;

class ActivityController extends BaseController
{
    /**
     * 互动预约
     */
    public function indexAction()
    {
        $basePicPath = C('SITE_URL') . '/Public/MobileHome/';
        $list = array(
            0 => array(
                'name' => '活动体验预约',
                'description' => '',
                'pic' => $basePicPath . 'images/activity-1.png',
                'url' => U('Activity/activity'),
            ),
            1 => array(
                'name' => '特色课程预约',
                'description' => '',
                'pic' => $basePicPath . 'images/activity-2.png',
                'url' => U('About/index', array('id' => 26)),
//                'url' => U('Activity/courseApply'),
            ),
            2 => array(
                'name' => '返聘岗位预约',
                'description' => '',
                'pic' => $basePicPath . 'images/activity-3.png',
                'url' => U('About/index', array('id' => 27)),
//                'url' => U('Activity/jobApply'),
            ),
        );
        $returnData = json_encode($list);
        $this->assign('jsonData', $returnData);
        $global_config = array(
            'title' => C('SITE_NAME'),
            'keywords' => C('SITE_NAME'),
            'description' => C('SITE_NAME'),
        );
        $this->assign('global_config', $global_config);
        $this->assign('list', $list);
        $this->display();
    }

    public function activityAction()
    {
        $Activity = M('Activity');
        $condition = array();
        $count = $Activity->where($condition)->count();
        $Page = new Page($count, 50);
        $Page->setConfig('header', '');
        $Page->setConfig('prev', '上一页');
        $Page->setConfig('next', '下一页');
        $Page->setConfig('last', '');
        $show = $Page->show();
        $list = $Activity->where($condition)->order('id desc')->limit($Page->firstRow . ',' . $Page->listRows)->select();
        $this->assign('page', $show);
        $this->assign('list', $list);
        $global_config = array(
            'title' => '活动公告' . '-' . C('SITE_NAME'),
            'keywords' => '活动公告',
            'description' => '活动公告',
        );
        $this->assign('list', $list);
        $this->assign('global_config', $global_config);
        $this->display();
    }

    /**
     * 体验预约
     */
    public function activityApplyAction()
    {
        if (IS_POST) {
            $ActivityUser = D('ActivityUser');
            $data = $ActivityUser->create($_POST['ActivityUser']);
            if (false !== $data) {
                $insertId = $ActivityUser->add();
                if (false !== $insertId) {
                    $this->success('提交成功');
                } else {
                    $this->error('提交失败');
                }
            } else {
                $this->error($ActivityUser->getError());
            }
        } else {
            $activity_id = I('get.activity_id', 0, 'intval');
            $activity_list = D('Activity')->select();
            $this->assign('activity_list', $activity_list);
            $this->assign('activity_id', $activity_id);
            $this->display();
        }
    }

    /**
     * 课程报名
     */
    public function courseApplyAction()
    {
        if (IS_POST) {
            $CourseApply = D('CourseApply');
            $data = $CourseApply->create($_POST['CourseApply']);
            if (false !== $data) {
                $insertId = $CourseApply->add();
                if (false !== $insertId) {
                    $this->success('提交成功');
                } else {
                    $this->error('提交失败');
                }
            } else {
                $this->error($CourseApply->getError());
            }
        } else {
            $course_list = M('Course')->select();
            $this->assign('course_list', $course_list);
            $this->display();
        }
    }

    /**
     * 岗位报名
     */
    public function jobApplyAction()
    {
        if (IS_POST) {
            $JobApply = D('JobApply');
            $data = $JobApply->create($_POST['JobApply']);
            if (false !== $data) {
                $insertId = $JobApply->add();
                if (false !== $insertId) {
                    $this->success('提交成功');
                } else {
                    $this->error('提交失败');
                }
            } else {
                $this->error($JobApply->getError());
            }
        } else {
            $job_list = M('Job')->select();
            $this->assign('job_list', $job_list);
            $this->display();
        }
    }

    /**
     * 入驻申请
     */
    public function checkInApplyAction()
    {
        if (IS_POST) {
            $CheckInApply = D('CheckInApply');
            $data = $CheckInApply->create($_POST['CheckInApply']);
            if (false !== $data) {
                $insertId = $CheckInApply->add();
                if (false !== $insertId) {
                    $this->success('提交成功');
                } else {
                    $this->error('提交失败');
                }
            } else {
                $this->error($CheckInApply->getError());
            }
        } else {
            $this->display();
        }
    }
}